package com.example.myproject.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.myproject.model.Message;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;

@Mapper
public interface MessageMapper extends BaseMapper<Message> {
    @Select("SELECT * FROM messages WHERE conversation_id = #{conversationId} ORDER BY sent_at ASC")
    List<Message> findByConversationId(Long conversationId);

    @Select("SELECT * FROM messages WHERE conversation_id = #{conversationId} ORDER BY sent_at DESC LIMIT 1")
    Message findLastMessageByConversationId(Long conversationId);
}